package com.weiqiao.mall.rest;

import com.weiqiao.aop.log.Log;
import com.weiqiao.mall.domain.CarouseEntity;
import com.weiqiao.mall.service.ISlideshowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 轮播图控制层
 */
@RestController
@RequestMapping("api")
public class SlideshowController {

    @Autowired
    private ISlideshowService slideshowService;


    @Log("轮播图数据列表")
    @GetMapping("/slideshow-list")
    public ResponseEntity SlideshowList(HttpServletRequest request, Pageable pageable) {
        Map map = slideshowService.findCarouse(request, pageable);
        return new ResponseEntity(map, HttpStatus.OK);
    }

    @Log("轮播图数据集合")
    @GetMapping("/get-slide-list")
    public ResponseEntity getSlideList(HttpServletRequest request) {
        return new ResponseEntity(slideshowService.getSlideList(request), HttpStatus.OK);
    }

    @Log("删除单个轮播图")
    @PostMapping("/del-slideshow")
    public ResponseEntity delSlideshow(HttpServletRequest request) {
        Map map = slideshowService.deleteById(request);
        return new ResponseEntity(map, HttpStatus.OK);
    }

    @Log("保存单个轮播图")
    @PostMapping("/save-slideshow")
    public ResponseEntity saveSlideshow(@RequestBody CarouseEntity carouse) {
        Map map = slideshowService.saveSlideshow(carouse);
        return new ResponseEntity(map, HttpStatus.OK);
    }
}
